<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: ajax.column.php Sat Jul 18 12:45:06 CST 2009
 */

include "conf.inc";
header("Content-Type:text/html; charset="._CHARSET);

if ( empty($xoopsUser) || !is_object($xoopsUser)) {
    echo _NOPERM;
    exit();
}

$op = isset($_POST["op"]) ? trim($_POST["op"]) : "";
$column_id = isset($_POST["cid"]) ? intval($_POST["cid"]) : 0;

$column_handler = xoops_getmodulehandler("column","groups");
$groups_handler = xoops_getmodulehandler("groups","groups");
$threads_handler = xoops_getmodulehandler("threads","groups");
$posts_handler = xoops_getmodulehandler("posts","groups");
$_obj = $column_handler->get($column_id);
if ( false == getIsGroupsAdmin($_obj->getVar("group_id"),$xoopsUser->getVar("uid")) ) {
	exit();
}
switch ($op) {
    case "savecolumn":
        $column_name = isset($_POST["column_name"]) ? trim($_POST["column_name"]) : "";
        if ( empty($column_name) ) {
            exit();
        }
        if ( $column_handler->setColumn($column_id,$_obj->getVar("group_id"),$column_name) ) {
            echo $column_name;
        }
        exit();
    break;
    
    case "delcolumn":
        $column_id = isset($_POST["cid"]) ? intval($_POST["cid"]) : 0;
        if ( $column_handler->delete($_obj) ) {
            $criteria = new CriteriaCompo(new Criteria("column_id",$column_id));
            $threads_handler->updateAll("column_id",0,$criteria);
            $posts_handler->updateAll("column_id",0,$criteria);
        }
        exit();
        
    break;
    
    default:
        echo _NOPERM;
        exit();
    break;
}

?>